const errors = require('../errors')
const TokenUtil = require('../util/baseUtil/SecretUtil')
const ObjectUtil = require('../util/baseUtil/ObjectUtil')
const crypto = require('crypto')
var redis = require('redis');

/**
 *
 * @param req
 * @param res
 * @param next
 * 认证用户是否登录
 */
module.exports = function(req, res, next) {

    try {
        redisClient.get(req.body.token, function(err, data) {
            if (data == null) {
                res.send({ 'code': 401 })
                return false
            } else {

                req.body.openid = JSON.parse(data).openid
                req.body.unionid = JSON.parse(data).unionid
                req.body.session_key = JSON.parse(data).session_key
                next()
            }
        })
    } catch (e) {
        next(e)
    }
};